﻿@page "/roles"
@attribute [Authorize(Roles = BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS)]
@inherits BlazorAdmin.Helpers.BlazorComponent
@namespace BlazorAdmin.Pages.RolePage

<PageTitle>eShopOnWeb Admin: Manage Roles</PageTitle>

<h1>Manage Roles</h1>

@if (_roles == null)
{
    <Spinner></Spinner>
} 
else 
{
        <p class="esh-link-wrapper">
            <button class="btn btn-primary" @onclick="@(CreateClick)">
                Create New
            </button>
        </p>
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Actions</th>
                </tr>
            </thead>
        <tbody class="cursor-pointer">
            @foreach (var role in _roles){
                    <tr>
                        <td>@role.Name</td>
                        <td>
                            <button @onclick="@(() => EditClick(role.Id))" @onclick:stopPropagation="true" class="btn btn-primary">
                                Edit
                            </button>
                            <button @onclick="@(() => DetailsClick(role.Id,role.Name))" @onclick:stopPropagation="true" class="btn btn-success">
                                Manage Members
                            </button>
                            <button @onclick="@(() => DeleteClick(role.Id))" @onclick:stopPropagation="true" class="btn btn-danger">
                                Delete
                            </button>
                        </td>
                    </tr>

                }
        </tbody>
    </table>

    <Create OnSaveClick="ReloadRoles" @ref="CreateComponent"></Create>
    <Delete OnSaveClick="ReloadRoles" @ref="DeleteComponent"></Delete>
    <Edit OnSaveClick="ReloadRoles" @ref="EditComponent"></Edit>
    <Details @ref="DetailsComponent"></Details>
}